import React from 'react';
import Header from '@/pages/header';
import Left from '@/pages/main/left';
import styles from './index.less';
import { history } from 'umi';
import { Spin } from 'antd';
export default class Layout extends React.PureComponent {
  state = {
    spinning: true //管理loading状态
  }

  // 停止loading状态
  spinStopLoading = () => {
    this.setState({
      spinning: false
    })
  }

  // 开启loading状态
  spinLoading = () => {
    this.setState({
      spinning: true
    })
  }

  componentDidMount() {
    history.push('/sub1'); //页面刚进入默认到 sub1 页面下
    setTimeout(() => {
      this.spinStopLoading()
    }, 1000);
  }

  componentDidUpdate() {
    setTimeout(() => {
      this.spinStopLoading()
    }, 1000);
  }

  render(): React.ReactNode {
    return (
      <div className={styles.container}>
        <Header />
        <main className={styles.main}>
          <Left spinLoading={this.spinLoading} spinStopLoading={this.spinStopLoading} />
          <div className={styles.right}>
            <Spin tip="加载中" spinning={this.state.spinning}>
              {this.props.children}
            </Spin>
          </div>
        </main>
      </div>
    );
  }
}
